<html>
<head><meta charset="utf-8"><title>Multiple definitions of `__sync_fetch_and_add_4` · t-compiler/arm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/index.html">t-compiler/arm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html">Multiple definitions of `__sync_fetch_and_add_4`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240240262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240240262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Émile Grégoire <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240240262">(May 25 2021 at 19:47)</a>:</h4>
<p>Hi, I'm compiling a static library written in Rust that is used by a C++ project. On x86_x64 linux, everything works great. But when I compile with armv7-unknown-linux-gnueabihf, I get errors about multiple definition of <code>__sync_fetch_and_add_4</code>. I've found a similar issue here: <a href="https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=951765">https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=951765</a> However, the solution of putting <code>--allow-multiple-definition</code> doesn't feel right to me. Does someone have a clue why this is happening and how to sort this out? Thanks!</p>



<a name="240242321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240242321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Émile Grégoire <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240242321">(May 25 2021 at 20:02)</a>:</h4>
<p>Also, the symbols <code>__sync_fetch_and_add_4</code> and <code>__sync_fetch_and_add_8</code> seems to only be present on ARMv7 builds. I tried ARMv6 and ARMv8, and our Rust code never emits such symbols in the static library and the C++ compiles fine.</p>



<a name="240243248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240243248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Émile Grégoire <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240243248">(May 25 2021 at 20:08)</a>:</h4>
<p>Been searching some more, and I think I'm hitting the exact issue described by <span class="user-mention" data-user-id="116015">@Alex Crichton</span> here: <a href="https://github.com/rust-lang/rust/pull/70846#issuecomment-609921474">https://github.com/rust-lang/rust/pull/70846#issuecomment-609921474</a> Is it supposed to be fixed?</p>



<a name="240243582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240243582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240243582">(May 25 2021 at 20:11)</a>:</h4>
<p>FWIW I think the best fix nowadays is to, in Rust's compiler-builtins, flag the symbols as weak. That way they can get overwritten if something else provides them but otherwise they can also get pulled in still. I think we've done that for other common symbols like <code>memcpy</code></p>



<a name="240244018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240244018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Émile Grégoire <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240244018">(May 25 2021 at 20:14)</a>:</h4>
<p>Should I open an issue about it to get it flagged as weak? And use <code>--allow-multiple-definition</code> in the meantime?</p>



<a name="240244046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240244046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240244046">(May 25 2021 at 20:14)</a>:</h4>
<p>up to you! I don't manage these crates nowadasy</p>



<a name="240244141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240244141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Émile Grégoire <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240244141">(May 25 2021 at 20:15)</a>:</h4>
<p>Alright, thanks!</p>



<a name="240264856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/242906-t-compiler/arm/topic/Multiple%20definitions%20of%20%60__sync_fetch_and_add_4%60/near/240264856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/242906-t-compiler/arm/topic/Multiple.20definitions.20of.20.60__sync_fetch_and_add_4.60.html#240264856">(May 25 2021 at 23:54)</a>:</h4>
<p>I thought the <code>__sync_fetch_and_*</code> functions shouldnt be provided by rust, since only rust provides atomics on architectures that actually have them as instructions</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>